<!-- Modal -->
<div class="modal fade " id="addInvestProModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 60%">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">新增投资项目</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">项目</label>
                        <div class="col-sm-5">
                            <input type="hidden" id="addInvestProModal_id">
                            <select class="form-control select2" style="width: 100%;" id="addInvestProModal_productId">
                            </select>
                        </div>

                        <button type="button" class="btn btn-primary"
                                onclick="addInvestProModal_changeEnterType()">切换
                        </button>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">项目名称：</label>
                        <div class="col-sm-3">
                            <input id="addInvestProModal_productName" type="text" class="form-control"
                                   disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">

                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">期限（年）:</label>
                        <div class="col-sm-3">
                            <input id="addInvestProModal_timelimit" type="text" class="form-control">
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">收益率（%）：</label>
                        <div class="col-sm-3">
                            <input id="addInvestProModal_yield" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">规模（亿元）：</label>
                        <div class="col-sm-3">
                            <input id="addInvestProModal_investScale" type="text" class="form-control">
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">缴款时间：</label>
                        <div class="col-sm-3">
                            <input id="addInvestProModal_paymentDate" type="text" class="form-control" onClick="WdatePicker()">
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                                onclick="addInvestProModal_save()">保存
                        </button>
                    </div>
                    <!-- /.box-footer -->
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    function addInvestProModal_changeEnterType() {
        var type = $("#addInvestProModal_productName").attr("disabled");
        if (undefined == type) {
            $("#addInvestProModal_productId").removeAttr("disabled");
            $("#addInvestProModal_productName").val("");
            $("#addInvestProModal_productName").attr("disabled", "disabled");
        } else {
            $("#addInvestProModal_productId").attr("disabled", "disabled");
            $("#addInvestProModal_productId").val("");
            $("#addInvestProModal_productName").removeAttr("disabled");
        }
    }

    function addInvestProModal_init() {
        $("#addInvestProModal_productId").empty();
        $("#addInvestProModal_productId").removeAttr("disabled");
        $("#addInvestProModal_productName").val("");
        $("#addInvestProModal_productName").attr("disabled", "disabled");
        $("#addInvestProModal_id").val("");
        $("#addInvestProModal_timelimit").val("");
        $("#addInvestProModal_yield").val("");
        $("#addInvestProModal_investScale").val("");
        $("#addInvestProModal_paymentDate").val("");

    }

    function addInvestProModal_setValue(index) {
        var url = "/productinvest/product/list";
        if (index == "-1") {
            setFormValue(url, "addInvestProModal_productId");
            return;
        } else {
            var options = $("#table3").bootstrapTable("getData");
            var row = options[index];
            $("#addInvestProModal_timelimit").val(row.timelimit);
            $("#addInvestProModal_yield").val(row.yield);
            $("#addInvestProModal_investScale").val(row.investScale);
            $("#addInvestProModal_paymentDate").val(row.paymentDate);
            $("#addInvestProModal_id").val(row.id);
            setFormValue(url, "addInvestProModal_productId", row.productId);
        }
    }

    function addInvestProModal_save() {
        var productId = $("#addInvestProModal_productId").val();
        var productName = $("#addInvestProModal_productName").val();
        if ((productId == "" || undefined == productId) && (productName == "" || undefined == productName)) {
            toastr['error']('请输入项目', '提示');
            return;
        }
        var data = {
            productId: productId,
            productName: productName,
            timelimit: $("#addInvestProModal_timelimit").val(),
            yield: $("#addInvestProModal_yield").val(),
            investScale: $("#addInvestProModal_investScale").val(),
            paymentDate: $("#addInvestProModal_paymentDate").val(),
            institutionId: table3QueryParams().institutionId,
            id: $("#addInvestProModal_id").val(),
            investType: "2"
        };
        var url = "/productinvest/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table3").bootstrapTable("refresh");
                $("#addInvestProModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
